package com.zhifei.system.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xinrenxinshi.XrxsCommonService;
import com.xinrenxinshi.XrxsDepartmentService;
import com.xinrenxinshi.XrxsEmployeeService;
import com.xinrenxinshi.XrxsPayrollService;
import com.xinrenxinshi.common.EmpStatusEnum;
import com.xinrenxinshi.common.FetchChildEnum;
import com.xinrenxinshi.domain.DepartmentModel;
import com.xinrenxinshi.domain.EmployeeDetail;
import com.xinrenxinshi.domain.JobHeaderModel;
import com.xinrenxinshi.domain.report.PayrollReportArchiveBase;
import com.xinrenxinshi.exception.ApiException;
import com.xinrenxinshi.openapi.OpenapiResponse;
import com.xinrenxinshi.openapi.XrxsOpenapiClient;
import com.xinrenxinshi.request.*;
import com.xinrenxinshi.response.OpenapiTokenResponse;
import com.xinrenxinshi.response.PageResult;
import com.xinrenxinshi.response.PayrollReportArchiveDetailResponse;
import com.xinrenxinshi.response.PayrollReportArchivesResponse;
import com.zhifei.common.core.redis.RedisCache;
import com.zhifei.common.utils.DateUtils;
import com.zhifei.common.utils.DispatcherUtils;
import com.zhifei.common.utils.Result;
import com.zhifei.common.utils.StringUtils;
import com.zhifei.system.domain.*;
import com.zhifei.system.mapper.XrxsEmployeeMapper;
import com.zhifei.system.service.*;
import com.zhifei.system.util.LocalCacheClient;
import kingdee.bos.webapi.client.K3CloudApiClient;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.sql.Wrapper;
import java.text.ParseException;
import java.util.*;
import java.util.concurrent.TimeUnit;

@Service
public class XrxsServiceImpl implements XrxsService {

    public static final String APP_KEY = "apppZsW5MwUq6LJCxcQWKDjVqW41AmFC";
    public static final String APP_SECRET = "wIvPH9WsoQdsPnuF7JeT";
    @Autowired
    private XrxsCallbackService xrxsCallbackService;
    @Autowired
    private XrxsPositionService xrxsPositionService;
    @Autowired
    private EmployeeSalaryService employeeSalaryService;
    @Autowired
    private EmployeeService employeeService;
    @Autowired
    private EmployeeMonthService employeeMonthService;
    @Autowired
    private XrxsEmployeeMapper xrxsEmployeeMapper;
    @Autowired
    private JdService jdService;
    @Autowired
    private RedisCache redisCache;

//    @Override
//    public Map<String, String> callBack(String sign, JSONObject json) {
//        Map<String, String> map = new HashMap<>();
//        map.put("message","success");
//        try {
//            String type = json.getString("type");
//            xrxsCallbackService.add(sign,json.toJSONString());//新增本地调用数据记录
//            if(type.equals("employee_entry")){//员工入职
//                String userName = json.getString("name");//员工姓名
//                String userMobile = json.getString("mobile");//员工手机号
//                JSONObject fieldsJson = json.getJSONObject("fields");
//                String userId = fieldsJson.getString("工号");//员工工号
//                String recruitHr = fieldsJson.getString("招聘HR");//招聘专员
//                String employeeId = json.getString("employeeId");//员工id
//                String entryDate = json.getString("entryDate");//入职时间
//                String accessToken = this.getAccessToken();
//                EmployeeInfoRequest request = new EmployeeInfoRequest(accessToken);
//                request.setEmployeeId(employeeId);
//                request.setStatus(EmpStatusEnum.ON_JOB);
//                OpenapiResponse<EmployeeDetail> employee = XrxsEmployeeService.getDetailEmployee(request);
//                Map<String, String> userFields = employee.getData().getFields();
//                String userDeptId = userFields.get("部门");
//                DepartmentListRequest departmentListRequest = new DepartmentListRequest(accessToken);
//                departmentListRequest.setDepartmentId(userDeptId);
//                OpenapiResponse<List<DepartmentModel>> departmentList = XrxsDepartmentService.getDepartmentList(departmentListRequest);
//                List<DepartmentModel> departmentModelList = departmentList.getData();
//                if(departmentModelList!=null && departmentModelList.size()>0){
//                    DepartmentModel departmentModel = departmentModelList.get(0);
//                    if(!departmentModel.getParentId().equals("0a61e125245f4b08be686692c98c6098")){//如果上级部门非外派项目组，不同步
//                        return map;
//                    }
//                }
//                String positionId = userFields.get("岗位");
//                String k3cloudPositionId = null;
//                String k3cloudRankId = null;
//                XrxsPositionEntity xrxsPositionEntity = xrxsPositionService.getByPositionId(positionId);
//                if(xrxsPositionEntity!=null && StringUtils.isNotEmpty(xrxsPositionEntity.getK3cloudId())){
//                    k3cloudPositionId = xrxsPositionEntity.getK3cloudId();
//                }
//                String rank = userFields.get("职级");
//                if(StringUtils.isNotEmpty(rank)){
//                    if(rank.equals("初级")){
//                        k3cloudRankId = "CJ";
//                    }else if(rank.equals("初中级")){
//                        k3cloudRankId = "CZJ";
//                    }else if(rank.equals("中级")){
//                        k3cloudRankId = "ZJ";
//                    }else if(rank.equals("中高级")){
//                        k3cloudRankId = "ZGJ";
//                    }else if(rank.equals("高级")){
//                        k3cloudRankId = "GJ";
//                    }
//                }
//                String monthPay = userFields.get("月薪");
//                String quoteMonthPay = userFields.get("报价月薪");
//                //新增数据到金蝶系统物料
//                jdService.addK3cloudMaterial(userId,userName,userMobile,k3cloudPositionId,k3cloudRankId,monthPay,quoteMonthPay);
//                //新增数据到数据中台employee表中
//                addEmployee(userId,userName,xrxsPositionEntity.getName(),rank,DateUtils.parseDate(entryDate),new BigDecimal(monthPay),recruitHr);
//                //新增到xrxs_employee表中
//                addXrxsEmployee(userId,userDeptId,userName,userMobile,entryDate,recruitHr);
//            }else if(type.equals("employee_dismiss")){//员工离职
//                String accessToken = this.getAccessToken();
//                String employeeId = json.getString("employeeId");//员工id
//                String dismissDate = json.getString("dismissDate");//离职日期
//                EmployeeInfoRequest request = new EmployeeInfoRequest(accessToken);
//                request.setEmployeeId(employeeId);
//                request.setStatus(EmpStatusEnum.OFF_JOB);
//                OpenapiResponse<EmployeeDetail> employee = XrxsEmployeeService.getDetailEmployee(request);
//                Map<String, String> userFields = employee.getData().getFields();
//                String jobNum = userFields.get("工号");
//                //employee表修改该员工状态为离职
//                employeeService.dismissEmployee(jobNum,dismissDate);
//            }else if(type.equals("employee_update")) {//员工信息更新
//                String accessToken = this.getAccessToken();
//                String employeeId = json.getString("employeeId");//员工id
//                EmployeeInfoRequest request = new EmployeeInfoRequest(accessToken);
//                request.setEmployeeId(employeeId);
//                request.setStatus(EmpStatusEnum.ON_JOB);
//                OpenapiResponse<EmployeeDetail> employee = XrxsEmployeeService.getDetailEmployee(request);
//                Map<String, String> userFields = employee.getData().getFields();
//                String positionId = userFields.get("岗位");
//                XrxsPositionEntity xrxsPositionEntity = xrxsPositionService.getByPositionId(positionId);
//                String userRank = userFields.get("职级");
//                String monthPay = userFields.get("月薪");
//                String recruitHr = userFields.get("招聘HR");
//                String jobNum = userFields.get("工号");
//                employeeService.updateEmployee(jobNum,xrxsPositionEntity.getName(),userRank,new BigDecimal(monthPay),recruitHr);
//                //如果部门发生改变则执行调岗
//                String deptId = userFields.get("部门");
//                QueryWrapper queryWrapper = new QueryWrapper();
//                queryWrapper.eq("employee_no",jobNum);
//                XrxsEmployeeEntity xrxsEmployeeEntity = xrxsEmployeeMapper.selectOne(queryWrapper);
//                if(xrxsEmployeeEntity!=null){
//                    if(!deptId.equals(xrxsEmployeeEntity.getDeptId())){
//                        employeeService.updatePost(jobNum,DateUtils.getDate());
//                        xrxsEmployeeMapper.updateDeptId(jobNum,deptId);
//                    }
//                }
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return map;
//    }

//    public void addEmployee(String jobNum,String fullName,String userPost,String userRank,Date admissionDate,BigDecimal monthPay,String recruitHr){
//        EmployeeEntity employeeEntity = new EmployeeEntity();
//        employeeEntity.setProjectType(2);//默认为2，如果纷享销客中订单明细匹配到会修改为1
//        employeeEntity.setJobNum(jobNum);
//        employeeEntity.setFullName(fullName);
//        employeeEntity.setUserPost(userPost);
//        employeeEntity.setUserRank(userRank);
//        employeeEntity.setAdmissionDate(admissionDate);
//        employeeEntity.setMonthPay(monthPay);
//        employeeEntity.setRecruitHr(recruitHr);
//        employeeEntity.setEmployeeStatus(1);
//        employeeService.save(employeeEntity);
//    }
//
//    public void addXrxsEmployee(String jobNum,String deptId,String name,String mobile,String entryDate,String recruitHr){
//        XrxsEmployeeEntity xrxsEmployeeEntity = new XrxsEmployeeEntity();
//        xrxsEmployeeEntity.setName(name);
//        xrxsEmployeeEntity.setMobile(mobile);
//        xrxsEmployeeEntity.setEntryDate(entryDate);
//        xrxsEmployeeEntity.setRecruitHr(recruitHr);
//        xrxsEmployeeEntity.setEmployeeNo(jobNum);
//        xrxsEmployeeEntity.setDeptId(deptId);
//        xrxsEmployeeMapper.insert(xrxsEmployeeEntity);
//    }
//
//
//
//    @Override
//    public OpenapiResponse<List<JobHeaderModel>> listJob() {
//        OpenapiResponse<List<JobHeaderModel>> jobList = null;
//        try {
//            String accessToken = this.getAccessToken();
//            DepartmentJobGetRequest request = new DepartmentJobGetRequest(accessToken);
//            jobList = XrxsDepartmentService.getJobList(request);
//            return jobList;
//        } catch (ApiException e) {
//            e.printStackTrace();
//        }
//        return jobList;
//    }


//    /**
//     * 签名算法
//     *
//     * @param content      签名明文
//     * @return 签名信息
//     * @throws Exception
//     */
//    public static String hmacSha1Encrypt(String content) throws Exception {
//        byte[] keyBytes = APP_SECRET.getBytes(StandardCharsets.UTF_8);
//        SecretKeySpec localSecretKeySpec = new SecretKeySpec(keyBytes, "HmacSHA1");
//        Mac localMac = Mac.getInstance("HmacSHA1");
//        localMac.init(localSecretKeySpec);
//        byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
//        localMac.update(contentBytes);
//        return URLEncoder.encode(Base64.encodeBase64String(localMac.doFinal()),"utf-8");
//    }
//
//    public String getAccessToken(){
//        String accessToken = redisCache.getCacheObject("xrxs_access_token");
//        if(StringUtils.isEmpty(accessToken)) {
//            try {
//                XrxsOpenapiClient.init(APP_KEY, APP_SECRET);// 初始化
//                XrxsOpenapiClient openapiClient = XrxsOpenapiClient.getInstance(); // 获取XrxsOpenapiClient实例
//                OpenapiTokenResponse token = XrxsCommonService.getAccessToken();// 获取token，建议这里对token做缓存处理
//                accessToken = token.getAccess_token();
//                redisCache.setCacheObject("xrxs_access_token", accessToken, 7200, TimeUnit.SECONDS);
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//        return null;
//    }
//
//
//    @Override
//    public Result listExpatriateOffjob() {
//        List<EmployeeDetail> employeeDetailList = new ArrayList<>();
//        try {
//            String accessToken = this.getAccessToken();
//            EmployeeDetailInfoListRequest employeeRequest = new EmployeeDetailInfoListRequest(accessToken);
//            for(int k=0;k<=2;k++){
//                employeeRequest.setDepartmentId("0a61e125245f4b08be686692c98c6098");
//                employeeRequest.setFetchChild(FetchChildEnum.CONTAINS_DEPARTMENT);
//                employeeRequest.setPageNo(k);
//                employeeRequest.setPageSize(100);
////                employeeRequest.setModtime(DispatcherUtils.parseInteger(DateUtils.getMonthBegin()));
////                employeeRequest.setModtime(1661961600);
//            employeeRequest.setStatus(EmpStatusEnum.ON_JOB);
//                OpenapiResponse<PageResult<EmployeeDetail>> employeeOpenapiResponse = XrxsEmployeeService.getDetailEmployeeList(employeeRequest);
//                employeeDetailList.addAll(employeeOpenapiResponse.getData().getResult());
//                int totalPageSize = employeeOpenapiResponse.getData().getTotalPageSize().intValue();
//                for(int i=1;i<totalPageSize;i++){
//                    EmployeeDetailInfoListRequest employeeRequestItem = new EmployeeDetailInfoListRequest(accessToken);
//                    employeeRequestItem.setDepartmentId("0a61e125245f4b08be686692c98c6098");
//                    employeeRequestItem.setFetchChild(FetchChildEnum.CONTAINS_DEPARTMENT);
//                    employeeRequestItem.setPageNo(i);
//                    employeeRequestItem.setPageSize(100);
//                    employeeRequestItem.setStatus(EmpStatusEnum.ON_JOB);
//                    OpenapiResponse<PageResult<EmployeeDetail>> employeeOpenapiResponseItem = XrxsEmployeeService.getDetailEmployeeList(employeeRequestItem);
//                    employeeDetailList.addAll(employeeOpenapiResponseItem.getData().getResult());
//                }
//            }
//            for(EmployeeDetail employeeDetail : employeeDetailList){
//                String name = employeeDetail.getName();//员工名字
//                String mobile = employeeDetail.getMobile();//手机号
//                String entryDate = employeeDetail.getEntryDate();//入职时间
//                //入场时间
//                //出项时间
//                Map<String, String> employeeFields = employeeDetail.getFields();//员工字段
//                String recruitHr = employeeFields.get("招聘HR");//招聘专员
//                String employeeNo = employeeFields.get("工号");//工号
//                String dismissionDate = employeeDetail.getDismissionDate();//离职时间
//                //预计出项时间（项目周期+入场时间、一个月内显示红色）
//                //状态（蓝色表示在项、红色表示离职、黄色表示在职出项，鼠标悬浮上去显示提示文字）
//                System.out.println("***************************************************************");
////                employeeService.dismissEmployee(employeeNo,dismissionDate);
////                    XrxsEmployeeEntity xrxsEmployeeEntity = new XrxsEmployeeEntity();
////                    xrxsEmployeeEntity.setName(name);
////                    xrxsEmployeeEntity.setMobile(mobile);
////                    xrxsEmployeeEntity.setEntryDate(entryDate);
////                    xrxsEmployeeEntity.setRecruitHr(recruitHr);
////                    xrxsEmployeeEntity.setEmployeeNo(employeeNo);
////                    xrxsEmployeeMapper.insert(xrxsEmployeeEntity);
//            }
//        } catch (ApiException e) {
//            e.printStackTrace();
//        }
//        return Result.success(employeeDetailList);
//    }

//    @Override
//    public Result listWages(String yearmo) {
//        String accessToken = this.getAccessToken();
//        PayrollReportArchivesRequest request = new PayrollReportArchivesRequest(accessToken);
////        String yearmo = DateUtils.parseDateToStr("yyyyMM", DateUtils.addMonths(new Date(),-1));
////        String yearmo = "202205";
//        Date yearmoDate = null;
//        try {
//            yearmoDate = DateUtils.parseDate(yearmo,"yyyyMM");
//        } catch (ParseException e) {
//        }
//        QueryWrapper wrapper = new QueryWrapper();
//        wrapper.eq("month",yearmoDate);
//        Integer employeeSalaryCount = employeeSalaryService.count(wrapper);
//        if(employeeSalaryCount>0){
//            return Result.success();
//        }
//        request.setYearmo(yearmo);
//        OpenapiResponse<PayrollReportArchiveDetailResponse> reportArchiveDetail = null;
//        try {
//            OpenapiResponse<PayrollReportArchivesResponse> reportArchives = XrxsPayrollService.getReportArchives(request);
//            PayrollReportArchiveDetailRequest payrollReportArchiveDetailRequest = new PayrollReportArchiveDetailRequest(accessToken);
//            if(reportArchives.getData()==null){
//                return Result.success();
//            }
//            List<PayrollReportArchiveBase> payrollReportArchiveBaseList = reportArchives.getData().getArchiveReportList();
//            PayrollReportArchiveBase payrollReportArchiveBase = payrollReportArchiveBaseList.get(payrollReportArchiveBaseList.size()-1);
//            payrollReportArchiveDetailRequest.setReportId(payrollReportArchiveBase.getReportId());
//            payrollReportArchiveDetailRequest.setSubReportId(payrollReportArchiveBase.getSubReportId());
//            reportArchiveDetail = XrxsPayrollService.getReportArchiveDetail(payrollReportArchiveDetailRequest);
//        } catch (ApiException e) {
//            e.printStackTrace();
//        }
//        List<String> reportDetailList = reportArchiveDetail.getData().getReportDetailList();
//        List<EmployeeEntity> employeeEntityList = employeeService.listDistinctEmployee();
//        for(String reportDetailListStr : reportDetailList){
//            List<String> reportDetail = Arrays.asList(reportDetailListStr.replaceAll("\"","").replaceAll("]","").split(","));
//            String deptName = reportDetail.get(4);//部门
//            if(deptName.equals("外派项目") && reportDetail.size()>16){
//                System.out.println("name:"+reportDetail.get(0));
//                String jobNum = reportDetail.get(2);//工号
//                String attendanceRequired = StringUtils.isEmpty(reportDetail.get(17))?"0":reportDetail.get(17);//甲方应出勤
//                String actualAttendance = StringUtils.isEmpty(reportDetail.get(18))?"0":reportDetail.get(18);//甲方实际出勤
//                String totalPayrollPayable = StringUtils.isEmpty(reportDetail.get(19))?"0":reportDetail.get(19);//应发工资总额
//                String afterTaxPay = StringUtils.isEmpty(reportDetail.get(37))?"0":reportDetail.get(37);//税后实发
//                String companyLaborCost = StringUtils.isEmpty(reportDetail.get(42))?"0":reportDetail.get(42);//企业人工成本
//                String personalSocialSecurity = StringUtils.isEmpty(reportDetail.get(31))?"0":reportDetail.get(31);//个人社保
//                String personalMedicalInsurance = StringUtils.isEmpty(reportDetail.get(33))?"0":reportDetail.get(33);//个人医保
//                String personalAccumulationFund = StringUtils.isEmpty(reportDetail.get(35))?"0":reportDetail.get(35);//个人公积金
//                String withholdingIncomeTax = StringUtils.isEmpty(reportDetail.get(36))?"0":reportDetail.get(36);//本月代扣个税
//                String adjustmentAmount = StringUtils.isEmpty(reportDetail.get(27))?"0":reportDetail.get(27);//调整金额
//                String companySocialSecurity = StringUtils.isEmpty(reportDetail.get(39))?"0":reportDetail.get(39);//公司社保
//                String companyMedicalInsurance = StringUtils.isEmpty(reportDetail.get(40))?"0":reportDetail.get(40);//公司医保
//                String companyAccumulationFund = StringUtils.isEmpty(reportDetail.get(41))?"0":reportDetail.get(41);//公司公积金
//                //记录外派人员薪资发放记录明细表
//                EmployeeSalaryEntity employeeSalaryEntity = new EmployeeSalaryEntity();
//                employeeSalaryEntity.setJobNum(jobNum);
//                employeeSalaryEntity.setMonth(yearmoDate);
//                employeeSalaryEntity.setAttendanceRequired(attendanceRequired);
//                employeeSalaryEntity.setActualAttendance(actualAttendance);
//                employeeSalaryEntity.setTotalPayrollPayable(new BigDecimal(totalPayrollPayable));
//                employeeSalaryEntity.setAfterTaxPay(new BigDecimal(afterTaxPay));
//                employeeSalaryEntity.setCompanyLaborCost(new BigDecimal(companyLaborCost));
//                employeeSalaryEntity.setPersonalSocialSecurity(new BigDecimal(personalSocialSecurity));
//                employeeSalaryEntity.setPersonalMedicalInsurance(new BigDecimal(personalMedicalInsurance));
//                employeeSalaryEntity.setPersonalAccumulationFund(new BigDecimal(personalAccumulationFund));
//                employeeSalaryEntity.setWithholdingIncomeTax(new BigDecimal(withholdingIncomeTax));
//                employeeSalaryEntity.setAdjustmentAmount(new BigDecimal(adjustmentAmount));
//                employeeSalaryEntity.setCompanySocialSecurity(new BigDecimal(companySocialSecurity));
//                employeeSalaryEntity.setCompanyMedicalInsurance(new BigDecimal(companyMedicalInsurance));
//                employeeSalaryEntity.setCompanyAccumulationFund(new BigDecimal(companyAccumulationFund));
//                employeeSalaryService.save(employeeSalaryEntity);
//                //记录外派人员每月实际详情表
//                for(EmployeeEntity employeeEntity : employeeEntityList){
//                    if(employeeEntity.getJobNum().equals(jobNum)){
//                        EmployeeMonthEntity employeeMonthEntity = new EmployeeMonthEntity();
//                        employeeMonthEntity.setJobNum(jobNum);
//                        employeeMonthEntity.setFullName(employeeEntity.getFullName());
//                        employeeMonthEntity.setCustomerName(employeeEntity.getCustomerName());
//                        employeeMonthEntity.setProjectName(employeeEntity.getProjectName());
//                        employeeMonthEntity.setMonth(yearmoDate);
//                        employeeMonthEntity.setSettlementAmount(null);
//                        employeeMonthEntity.setCollectionAmount(null);
//                        employeeMonthEntity.setCollectionDate(null);
//                        employeeMonthEntity.setQuoteMonthPay(employeeEntity.getQuoteMonthPay());
//                        employeeMonthEntity.setCompanyLaborCost(new BigDecimal(companyLaborCost));
//                        employeeMonthEntity.setTaxRate(employeeEntity.getTaxRate());
//                        BigDecimal quoteMonthPay = employeeMonthEntity.getQuoteMonthPay();
//                        BigDecimal taxRate = employeeMonthEntity.getTaxRate();
//                        BigDecimal CompanyLaborCost = employeeMonthEntity.getCompanyLaborCost();
//                        BigDecimal taxAmount = quoteMonthPay.multiply((taxRate.divide(new BigDecimal(100),2, RoundingMode.HALF_UP)));//税额（报价月薪*税率）
//                        employeeMonthEntity.setTaxAmount(taxAmount);
//                        BigDecimal grossProfit = quoteMonthPay.subtract(CompanyLaborCost).subtract(taxAmount);//毛利（报价-薪资-社保公积金-税额）
//                        employeeMonthEntity.setGrossProfit(grossProfit);
//                        BigDecimal grossProfitRate = grossProfit.divide(quoteMonthPay,2,RoundingMode.HALF_UP);//毛利率（毛利/报价，如有调整实时更新，低于18%显示红色预警）
//                        employeeMonthEntity.setGrossProfitRate(grossProfitRate);
//                        BigDecimal companyManagementCost = quoteMonthPay.multiply(new BigDecimal(0.1));//公司管理成本（报价*10%）
//                        employeeMonthEntity.setCompanyManagementCost(companyManagementCost);
//                        BigDecimal riskReserve = quoteMonthPay.multiply(new BigDecimal(0.05));//风险储备金（报价*5%）
//                        employeeMonthEntity.setRiskReserve(riskReserve);
//                        BigDecimal travelExpenses = BigDecimal.ZERO;//差旅费用（初始值为0，后续接口取金蝶中人员差旅成本）
//                        employeeMonthEntity.setTravelExpenses(travelExpenses);
//                        BigDecimal marketingSubsidies = quoteMonthPay.multiply(new BigDecimal(0.01));//市场营销补贴（报价*1%）
//                        employeeMonthEntity.setMarketingSubsidies(marketingSubsidies);
//                        BigDecimal financialExpenses = quoteMonthPay.multiply(new BigDecimal(0.012));//财务费用（报价*1.2%）
//                        employeeMonthEntity.setFinancialExpenses(financialExpenses);
//                        BigDecimal salesCommission = BigDecimal.ZERO;
//                        if(grossProfitRate.compareTo(new BigDecimal(0.1))<=0){
//                            salesCommission = BigDecimal.ZERO;
//                        }else if(grossProfitRate.compareTo(new BigDecimal(0.1))>0 && grossProfitRate.compareTo(new BigDecimal(0.2))<=0){
//                            salesCommission = grossProfit.multiply(new BigDecimal(0.01));
//                        }else if(grossProfitRate.compareTo(new BigDecimal(0.2))>0 && grossProfitRate.compareTo(new BigDecimal(0.3))<=0){
//                            salesCommission = grossProfit.multiply(new BigDecimal(0.03));
//                        }else if(grossProfitRate.compareTo(new BigDecimal(0.3))>0){
//                            salesCommission = grossProfit.multiply(new BigDecimal(0.05));
//                        }
//                        employeeMonthEntity.setSalesCommission(salesCommission);//销售提成（毛利率<=18%为0，毛利率在18到30%为毛利*2%，毛利率在30%以上为毛利*2.5%）
//                        BigDecimal talentServiceCommission = grossProfit.multiply(new BigDecimal(0.02));//人才服务部提成（毛利*2%）
//                        employeeMonthEntity.setTalentServiceCommission(talentServiceCommission);
//                        BigDecimal netProfit = grossProfit.subtract(companyManagementCost).subtract(riskReserve).subtract(travelExpenses)
//                                .subtract(marketingSubsidies).subtract(financialExpenses).subtract(salesCommission).subtract(talentServiceCommission);//纯利（毛利-公司管理成本-风险储备金-差旅费用-市场营销补贴-财务费用-销售提成-人才服务部提成）
//                        employeeMonthEntity.setNetProfit(netProfit);
//                        BigDecimal netProfitRate = netProfit.divide(quoteMonthPay,2,RoundingMode.HALF_UP);//纯利率（纯利/报价）
//                        employeeMonthEntity.setNetProfitRate(netProfitRate);
//                        employeeMonthEntity.setServiceManager(employeeEntity.getServiceManager());
//                        employeeMonthEntity.setRecruitHr(employeeEntity.getRecruitHr());
//                        employeeMonthService.save(employeeMonthEntity);
//                        //更新employee表薪资和社保公积金
////                        employeeEntity.setMonthPay(employeeSalaryEntity.getTotalPayrollPayable());
//                        employeeEntity.setSocialSecurity(employeeSalaryEntity.getCompanySocialSecurity().add(employeeSalaryEntity.getCompanyMedicalInsurance())
//                                .add(employeeSalaryEntity.getCompanyAccumulationFund()));
//                        employeeService.caclPrice(employeeEntity);
//                    }
//                }
//            }
//        }
//        return Result.success(reportArchiveDetail);
//    }

}
